package com.df.gamesynctest.entity;

import com.df.gamesynctest.msg.MsgWrapper;
import com.df.gamesynctest.msg.S2C_SynAroundObjs;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserManager {

    private   static UserManager userManager = new UserManager();
    private UserManager(){}

    public static UserManager getInstance(){
        return userManager;
    }

    public Map<Integer,Player> id2player = new HashMap<>();


    public void broadCastMsg(List<Player> players,Object msg){
        if(players==null || players.isEmpty()){
            return;
        }
        if(msg==null){
            return;
        }
        MsgWrapper msgWrapper = MsgWrapper.createMsgWrapper(msg);
        for (Player player : players) {
            player.channel.writeAndFlush(msgWrapper);
        }
    }

    public void sendMsg(Player player, S2C_SynAroundObjs msg) {
        MsgWrapper msgWrapper = MsgWrapper.createMsgWrapper(msg);
        player.channel.writeAndFlush(msgWrapper);
    }
}
